/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carrello.impl.boundary.user;

import carrello.impl.boundary.AbstractUI;
import carrello.impl.controller.user.SearchProductCTRL;
import carrello.model.entities.Product;
import java.util.List;

/**
 *
 * @author Mehdi
 */
public class SearchProductUI extends AbstractUI{
    
    private String keyword = null;
    private List<Product> products = null;
    private int numOfProducts = 0;
    private SearchProductCTRL searchProductCtrl = new SearchProductCTRL();

    /**
     * @return the keyword
     */
    public String getKeyword() {
        return keyword;
    }

    /**
     * @param keyword the keyword to set
     */
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    /**
     * @return the products
     */
    public List<Product> getProducts() {
        return products;
    }

    /**
     * @param products the products to set
     */
    public void setProducts(List<Product> products) {
        this.products = products;
    }
    
    @Override
    public String execute(){
        if (keyword != null){
            search(keyword);
        }
        return SUCCESS;
    }
    
    public void search(String keyword) {
        products = searchProductCtrl.searchProduct(keyword);
        if (!products.isEmpty()) {
            setNumOfProducts(products.size());
        }
        
    }

    /**
     * @return the numOfProducts
     */
    public int getNumOfProducts() {
        return numOfProducts;
    }

    /**
     * @param numOfProducts the numOfProducts to set
     */
    public void setNumOfProducts(int numOfProducts) {
        this.numOfProducts = numOfProducts;
    }
    
}
